home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / caratulasdecine (ES).ifs < prev    next >
Text File  |  2005-02-22  |  7KB  |  204 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=japg2000 (japg2000@terra.es)
  8. Title=CaratulasDeCine
  9. Description=Picture importation script for www.caratulasdecine.com
  10. Site=www.caratulasdecine.com
  11. Language=ES
  12. Version=1.1
  13. Requires=3.5.0
  14. Comments=
  15. License=The source code of the script can be used in another program only if full credits to script author and a link to Ant Movie Catalog website are given in the About box or in the documentation of the program.|
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program CaratulasdecineImport;
  23. var
  24.   Title: string;
  25.  
  26. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  27. var
  28.   i: Integer;
  29. begin
  30.   result := -1;
  31.   if StartAt < 0 then
  32.     StartAt := 0;
  33.   for i := StartAt to List.Count-1 do
  34.     if Pos(Pattern, List.GetString(i)) <> 0 then
  35.     begin
  36.       result := i;
  37.       Break;
  38.     end;
  39. end;
  40.  
  41. function EliminaInicio(S: string; CR: string): string;
  42. begin
  43.   result := S;
  44.   while Pos(CR, result) = 1 do
  45.   begin
  46.     Delete(result, 1, Length(CR));
  47.   end;
  48. end;
  49.  
  50. function CadenaEntre(var S: string; StartTag: string; EndTag: string): string;
  51. var
  52.   InicioPos: Integer;
  53. begin
  54.   InicioPos := Pos(StartTag, S);
  55.   Delete(S, 1, InicioPos + Length(StartTag) - 1);
  56.   InicioPos := Pos(EndTag, S);
  57.   result := copy(S, 1, InicioPos - 1);
  58.   Delete(S, 1, InicioPos + 1);
  59. end;
  60.  
  61. function PreparaTitulo(T: string): string;
  62. var
  63.   i: Integer;
  64. begin
  65.   result := AnsiLowerCase(T);
  66.   HTMLDecode(result);
  67.   result := StringReplace(result, chr(146), '');
  68.   result := StringReplace(result, chr(39), '');
  69.   result := StringReplace(result, '┤', '');
  70.   result := StringReplace(result, '`', '');
  71.   result := StringReplace(result, '"', '');
  72.   result := StringReplace(result, '┐', '');
  73.   result := StringReplace(result, '?', '');
  74.   result := StringReplace(result, 'í', '');
  75.   result := StringReplace(result, '!', '');
  76.   result := StringReplace(result, '.', '');
  77.   result := StringReplace(result, ',', '');
  78.   result := StringReplace(result, ':', '');
  79.   result := StringReplace(result, ';', '');
  80.   result := StringReplace(result, '-', '');
  81.   result := StringReplace(result, '/', '');
  82.   result := StringReplace(result, '\', '');
  83.   result := StringReplace(result, 'ß', 'a');
  84.   result := StringReplace(result, 'Θ', 'e');
  85.   result := StringReplace(result, 'φ', 'i');
  86.   result := StringReplace(result, '≤', 'o');
  87.   result := StringReplace(result, '·', 'u');
  88.   result := StringReplace(result, 'ⁿ', 'u');
  89.   result := StringReplace(result, '±', 'n');
  90. end;
  91.  
  92. function GetCaratulasDeCineDir(MovieTitle: string): string;
  93. var
  94.   PageOfLetter: Array of string;
  95.   C: Char;
  96.   Index: Integer;
  97. begin
  98.   Setarraylength(PageOfLetter,36);
  99.   PageOfLetter[0]:='0_9';  PageOfLetter[1]:='0_9';  PageOfLetter[2]:='0_9';  PageOfLetter[3]:='0_9';
  100.   PageOfLetter[4]:='0_9';  PageOfLetter[5]:='0_9';  PageOfLetter[6]:='0_9';  PageOfLetter[7]:='0_9';
  101.   PageOfLetter[8]:='0_9';  PageOfLetter[9]:='0_9';  PageOfLetter[10]:='a';   PageOfLetter[11]:='b';
  102.   PageOfLetter[12]:='c';   PageOfLetter[13]:='d';   PageOfLetter[14]:='e';   PageOfLetter[15]:='f_h';
  103.   PageOfLetter[16]:='f_h'; PageOfLetter[17]:='f_h'; PageOfLetter[18]:='i_k'; PageOfLetter[19]:='i_k';
  104.   PageOfLetter[20]:='i_k'; PageOfLetter[21]:='l';   PageOfLetter[22]:='m_n'; PageOfLetter[23]:='m_n';
  105.   PageOfLetter[24]:='o_q'; PageOfLetter[25]:='o_q'; PageOfLetter[26]:='o_q'; PageOfLetter[27]:='r_s';
  106.   PageOfLetter[28]:='r_s'; PageOfLetter[29]:='t_z'; PageOfLetter[30]:='t_z'; PageOfLetter[31]:='t_z';
  107.   PageOfLetter[32]:='t_z'; PageOfLetter[33]:='t_z'; PageOfLetter[34]:='t_z'; PageOfLetter[35]:='t_z';
  108.  
  109.   C := copy(MovieTitle, 1, 1);
  110.   if (C >= '0') and (C <= '9') then
  111.   begin
  112.      Index := Ord(C) - Ord('0');
  113.   end
  114.   else
  115.   begin
  116.      Index := 10 + Ord(C) - Ord('a');
  117.   end;
  118.  
  119.   result:='http://www.caratulasdecine.com/' + PageOfLetter[Index] + '.htm';
  120. end;
  121.  
  122. procedure AnalyzePageCaratulasDeCine(PageDir: string);
  123. var
  124.   CaratulasdecinePage, MoviePage: TStringList;
  125.   MovieDir, Line, LineTmp: string;
  126.   Encontrado, Salir, BeginPos, EndPos, LineNr, LineMov: Integer;
  127. begin
  128.   CaratulasdecinePage := TStringList.Create;
  129.   CaratulasdecinePage.Text := GetPage(PageDir);
  130.  
  131.   LineNr := FindLine('</big></big></big></big></big></big>', CaratulasdecinePage, 0);
  132.   LineNr := LineNr + 1;
  133.   Line := CaratulasdecinePage.GetString(LineNr);
  134.   Line := EliminaInicio(Line, ' ');
  135.   Salir := 0;
  136.   Encontrado := 0;
  137.   repeat
  138.     while (Pos('<br>', Line) = 0) and (Pos('</td>', Line) = 0) and (LineNr < 1000) do
  139.     begin
  140.       if copy(Line, Length(Line), 1) <> ' ' then
  141.         Line := Line + ' ';
  142.       LineNr := LineNr + 1;
  143.       LineTmp := CaratulasdecinePage.GetString(LineNr);
  144.       LineTmp := EliminaInicio(LineTmp, ' ');
  145.       Line := Line + LineTmp;
  146.     end;
  147.  
  148.     if Pos('</td>', Line) > 0 then
  149.       Salir := 1;
  150.  
  151.     if Pos('<a class="A" href="', Line) > 0 then
  152.     begin
  153.       MovieDir := 'http://www.caratulasdecine.com/' + CadenaEntre(Line, '<a class="A" href="', '">');
  154.     end
  155.     else
  156.     begin
  157.       MovieDir := Line;
  158.       MovieDir := CadenaEntre(MovieDir, '<a href="', 'class="A">');
  159.       while Pos('<a href="', MovieDir) > 0 do
  160.         MovieDir := CadenaEntre(MovieDir, '<a href="', 'class="A">');
  161.     end;
  162.  
  163.     Line := CadenaEntre(Line, '', '<');
  164.     Line := PreparaTitulo(Line);
  165.  
  166.     if Pos(Title, Line) > 0 then
  167.     begin
  168.       MoviePage := TStringList.Create;
  169.       MoviePage.Text := GetPage(MovieDir);
  170.       LineMov := FindLine('<p align="center"><img src="', MoviePage, 0);
  171.       Line := MoviePage.GetString(LineMov);
  172.       Line := CadenaEntre(Line, '<p align="center"><img src="', '" ');
  173.       Line := EliminaInicio(Line, '../');
  174.       GetPicture('http://www.caratulasdecine.com/' + Line);
  175.       Salir := 1;
  176.       Encontrado := 1;
  177.     end;
  178.  
  179.     LineNr := LineNr + 1;
  180.     if LineNr > 1000 then
  181.       Salir := 1;
  182.  
  183.     Line := CaratulasdecinePage.GetString(LineNr);
  184.     Line := EliminaInicio(Line, ' ');
  185.   until Salir = 1;
  186.  
  187.   if (Encontrado <> 1) then
  188.      ShowMessage('Titulo ' + Title + ' no encontrado en ' + PageDir)
  189. end;
  190.  
  191. begin
  192.   if CheckVersion(3,5,0) then
  193.   begin
  194.     Title := GetField(fieldTranslatedTitle);
  195.     if Title = '' then Title := GetField(fieldOriginalTitle);
  196.     Title := PreparaTitulo(Title);
  197.     Input('Importar de caratulasdecine.com', 'Por favor, introduce el titulo:', Title);
  198.     Title := PreparaTitulo(Title);
  199.  
  200.     AnalyzePageCaratulasDeCine(GetCaratulasDeCineDir(Title));
  201.   end else
  202.     ShowMessage('Este script necesita una versi≤n superior de Ant Movie Catalog (al menos la version 3.5.0)');
  203. end.
  204.